package org.mypofolio.model;

import java.text.ParseException;

import javax.swing.ImageIcon;
import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;

import org.apache.commons.configuration.ConfigurationException;
import org.mypofolio.gui.DataWithIcon;
import org.mypofolio.model.update.UpdateManager;


public class CurrencyTableModel extends AbstractTableModel {
	
  protected static final Class thisClass = CurrencyTableModel.class;	
  
  protected String[] columnNames = { "Date","Stock", "Description", "Amount","Qty",   "Total D", "Total A" };
  
  private DataModel dmodel;
  protected Object[][] data;
  private UpdateManager updateManager;
  
  // Constructor: calculate currency change to create the last column
  public CurrencyTableModel() throws ConfigurationException, ParseException {
	  dmodel=new DataModel();
	  dmodel.load();
	  updateManager =new UpdateManager(this);
	  this.data=dmodel.toArray(updateManager);
  }
  
  public UpdateManager getUpdateManager(){
	  return updateManager;
  }

  // Implementation of TableModel interface
  public int getRowCount() {
    return data.length;
  }

  public int getColumnCount() {
    return columnNames.length;
  }

  public Object getValueAt(int row, int column) {
    return data[row][column];
  }

  public Class getColumnClass(int column) {
	  if (data[0][column]==null){
		  return String.class;
	  }
    return (data[0][column]).getClass();
  }

  public String getColumnName(int column) {
    return columnNames[column];
  }
  
  @Override
	public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
	    data[rowIndex][columnIndex]=aValue;
	    this.fireTableCellUpdated(rowIndex, columnIndex);
	}




}